<template>
  <div class="map">
    <div id="container" tabindex="0"></div>
    <div class="input-card" style="width:19rem" v-show="path=='/distribution'">
      <div id="map-features" class="c">
        <div class="input-item">
          <input type="checkbox" name="mapStyle" value="bg" checked />
          <span class="input-text">区域面（bg）</span>
        </div>
        <div class="input-item">
          <input type="checkbox" name="mapStyle" value="road" checked />
          <span class="input-text">道路（road）</span>
        </div>
        <div class="input-item">
          <input type="checkbox" name="mapStyle" value="building" checked />
          <span class="input-text">建筑物（building）</span>
        </div>
        <div class="input-item">
          <input type="checkbox" name="mapStyle" value="point" checked />
          <span class="input-text">标注（point）</span>
        </div>
      </div>
    </div>
    <!-- <button @click="add" class="btn">点我</button> -->
  </div>
</template>
<script>
// import AMap from "AMap";

export default {
  props: {
    sensorArr: {
      type: Array,
      default: []
    },
    OffLine:{
      type:String,
      default:''
    },
    OLine:{
      type:String,
      default:''
    }
  },

  data(){
    return{
   
    }
  },
  watch: {
    sensorArr() {
      this.init();
    }
  
  },
  mounted() {
    this.init()
  },
  methods: {
  
    init() {
      var self=this
      // 路由地址
      let router = this.$route.path;
      var map = new AMap.Map("container", {
        resizeEnable: true,
        mapStyle: "amap://styles/dbc921cd58bfc91d309bb1809dc5d59b",
        features: ["bg", "road", "building", "point"]
      });
      var lnglats = this.sensorArr;
      var infoWindow = new AMap.InfoWindow({ offset: new AMap.Pixel(0, -30) });
      var OnLine = "";
      var OffLine = "";
      for (var i = 0, marker; i < lnglats.length; i++) {
        var marker = new AMap.Marker({
          icon: lnglats[i].rtuStatus == 0 ? self.OffLine :self.OLine,
          position: [lnglats[i].lng, lnglats[i].lat],
          map: map
        });
      }
      map.setFitView();
    }
  }
};
</script>
<style scoped>
/deep/ .amap-marker img {
  width: 40px;
}

.map {
  position: relative;
  width: 100%;
  height: 100%;
  position: relative;
}
#container {
  width: 100%;
  height: 100%;
}
.btn {
  position: absolute;
  z-index: 5;
  top: 50px;
}
#map-features {
  position: absolute;
  z-index: 999;
  bottom: 80px;
  right: 10px;
  background-color: rgba(0, 0, 0, 0.8);
  color: #ffffff;
}
/deep/ .amap-info-content {
  background: #0ac07e;
  color: #ffffff;
  font-size: 14px;
}
/deep/ .amap-info-content span {
  display: inline-block;
  width: 80px;
  background-color: #fff;
  color: #0ac07e;
  text-align: center;
}
</style>